package com.example.donghuihui.androidframe.basewebview;

import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.example.donghuihui.androidframe.BaseApplication;
import com.example.donghuihui.androidframe.utils.NetUtil;


/**
 * 自定义webviewclient。断网及receive error时跳转到指定页面
 */
public abstract class BaseWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (!NetUtil.isConnected(BaseApplication.getInstance())) {
            view.loadUrl("file:///android_asset/nowifi.htm");
            return true;
        }
//		else{
//			return onPreLoad(view, url);
//		}
        return false;
    }

    protected abstract boolean onPreLoad(WebView view, String url);

    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        super.onReceivedError(view, request, error);
//        view.loadUrl("file:///android_asset/nowifi.htm");
    }

}
